﻿using Bids.Core.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.OpenAccess;
using Telerik.OpenAccess.Metadata;
using Telerik.OpenAccess.Metadata.Fluent;
namespace Bids.Core.DomainObjects
{
	/// <summary>
	/// 评论
	/// </summary>
	[Serializable]
    public class Comment : IEntity
	{
		/// <summary>
		/// 
		/// </summary>
        public virtual int ID { set; get; }
		/// <summary>
		/// 投稿id
		/// </summary>
        public virtual int ContributionId { set; get; }
        /// <summary>
        /// 用户
        /// </summary>
        public virtual int UserId { get; set; }
		/// <summary>
		/// 评论类容
		/// </summary>
        public virtual string Content { set; get; }
		/// <summary>
		/// 评论时间
		/// </summary>
        public virtual DateTime CreateTime { set; get; }
        public virtual User User { get; set; }
        public virtual Contribution Contribution { get; set; }
        public static MappingConfiguration<Comment> CreateConfiguration()
        {
            var threadMapping = new MappingConfiguration<Comment>();
            threadMapping.MapType(t => new
            {
                t.ID,
                t.ContributionId,
                t.UserId,
                t.Content,
                t.CreateTime
            }).ToTable("Comments");
            threadMapping.HasProperty(t => t.ID).IsIdentity(KeyGenerator.Autoinc);
            threadMapping.HasAssociation(t => t.User).HasConstraint((t, d) => t.UserId == d.ID);
            //threadMapping.HasAssociation(t => t.Forum).WithOpposite(f => f.Threads).HasConstraint((t, f) => t.ForumId == f.Id);
            //threadMapping.HasAssociation(t => t.User).WithOpposite(u => u.Threads).HasConstraint((t, u) => t.UserId == u.Id);

            return threadMapping;
        }

	}
}

